﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Chinaer.Web
{
    public partial class zhongxingonggao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Chinaer.WCF.Services.ChinaerService chinaerService = new WCF.Services.ChinaerService();
            DTO.ZhongXinGongGaoDTO zhongxingonggaoDTO = new DTO.ZhongXinGongGaoDTO()
            {
                Title = this.txtTitle.Text,
                Content = this.txtContent.Text
            };
            Model.Common.JsonResult jsonResult = chinaerService.AddZhongXinGongGao(zhongxingonggaoDTO);
            Response.Write(jsonResult.Success);
            Bind();
        }

        private void Bind()
        {
            Chinaer.WCF.Services.ChinaerService chinaerService = new WCF.Services.ChinaerService();
            var result = chinaerService.GetAllZhongXinGongGao(Session["shangJiaID"].ToString(), "");
            this.gvList.DataSource = result;
            this.gvList.DataBind();

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string id = this.txtID.Text.Trim();
            Chinaer.WCF.Services.ChinaerService chinaerService = new WCF.Services.ChinaerService();
            var result = chinaerService.DeleteZhongXinGongGaoByID(id, "");
            Response.Write(result.Success);
            Bind();
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string isRead = this.txtIsRead.Text;
            string id = this.txtID.Text;
            string shangJiaID = Session["shangjiaid"].ToString();
            Chinaer.WCF.Services.ChinaerService chinaerService = new WCF.Services.ChinaerService();
            chinaerService.AddShangJiaIsReadZhongXinGongGao(new DTO.ShangJiaIsReadZhongXinGongGaoDTO()
            {
                ReadTime = DateTime.Now,
                ShangJiaID = shangJiaID,
                ZhongXinGongGaoID = id,
                IsRead = Convert.ToBoolean(isRead)
            });
            Bind();
        }
    }
}